import React from 'react'
import PropTypes from 'prop-types'

export default function Preload(props, context) {
  const { preload } = context
  const {
    as: Tag,
    name,
    ...restProps,
  } = props
  const content = preload[name]
  return (
    <Tag {...restProps}>{content}</Tag>
  )
}

Preload.defaultProps = {
  as: 'div',
}

Preload.contextTypes = {
  preload: PropTypes.object,
}